package com.ucomm.talent.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ucomm.talent.R;
import com.ucomm.talent.model.NewsInfo;

public class NewsInfoListAdapter extends BaseAdapter{
	
	private LayoutInflater layoutInflater;
	private ArrayList<NewsInfo> mData;
	
	public NewsInfoListAdapter(Context context,ArrayList<NewsInfo> mData) {
		this.layoutInflater = LayoutInflater.from(context);
		this.mData = mData;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
	        if (convertView == null) {

	            holder=new ViewHolder();

	            convertView = layoutInflater.inflate(R.layout.news_item_layout, null);
	            holder.title = (TextView) convertView.findViewById(R.id.title);
	            holder.news_id = (TextView)convertView.findViewById(R.id.news_id);
	            holder.datetime = (TextView)convertView.findViewById(R.id.datetime);
	            holder.description = (TextView) convertView.findViewById(R.id.description);
	            convertView.setTag(holder);

	        }else {
	            holder = (ViewHolder)convertView.getTag();
	        }
	        NewsInfo info = mData.get(position);
	        holder.title.setText(info.getTitle());
	        holder.news_id.setText(info.getNewsId()+"");
	        holder.datetime.setText(info.getDateTime());
	        holder.description.setText(info.getDescription());
	        return convertView;
	}
	final class ViewHolder{
		public TextView title;
		public TextView news_id;
		public TextView datetime;
		public TextView description;
	}
	public ArrayList<NewsInfo> getmData() {
		// TODO Auto-generated method stub
		return mData;
	} 
	
	
}
